package com.magicode.cms.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.magicode.cms.common.assist.UtilPath;
import com.magicode.cms.dao.ISpecialTopicDao;
import com.magicode.cms.dao.ISpecialTopicItemDao;
import com.magicode.cms.entiy.base.Article;
import com.magicode.cms.entiy.base.SpecialTopic;
import com.magicode.cms.entiy.base.SpecialTopicItem;
import com.magicode.cms.service.ISpecialTopicItemService;
import com.magicode.cms.service.ISpecialTopicService;
@Service("serviceSpecialTopicItem")
public class SpecialTopicItemServiceImpl extends BaseServiceImpl<SpecialTopicItem,ISpecialTopicItemDao> implements ISpecialTopicItemService,UtilPath {

	

	@Autowired
	@Qualifier("daoSpecialTopicItem")
	private ISpecialTopicItemDao specialTopicItemDao;

	

	public ISpecialTopicItemDao getSpecialTopicItemDao() {
		return specialTopicItemDao;
	}

	public void setSpecialTopicItemDao(ISpecialTopicItemDao specialTopicItemDao) {
		this.specialTopicItemDao = specialTopicItemDao;
	}

	@Override
	public List<Map<String, Object>> getBeanInfo() {
		List<Map<String, Object>> beaninfo = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(json_key, "title1");
		map.put(json_title, "节目名称");
		map.put("width", 150);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "title2");
		map.put(json_title, "版权公司");
		map.put("width", 150);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "title3");
		map.put(json_title, "制作公司");
		map.put("width", 150);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "title4");
		map.put(json_title, "播放地区");
		map.put("width", 150);
		beaninfo.add(map);
		return beaninfo;
	}

	@Override
	public String getHql(Map<String, String> querywhere) throws Exception {
		String hql ="from " +SpecialTopicItem.class.getName()+" "+entity_alias_name+" ";
		if(null!=querywhere && !querywhere.isEmpty()){
			hql += "where 1 = 1  ";  //and "+entity_alias_name+".isContribute = 0
			if(querywhere.containsKey(field_id)){
				hql = hql+" and "+entity_alias_name+".id = '"+querywhere.get(field_id)+"'";
			}
			if(querywhere.containsKey("title1")){
				hql = hql+" and "+entity_alias_name+".title1 like '%"+querywhere.get("title1")+"%'";
			}
			if(querywhere.containsKey("title2")){
				hql = hql+" and "+entity_alias_name+".title2 like '%"+querywhere.get("title2")+"%'";
			}
			if(querywhere.containsKey("title3")){
				hql = hql+" and "+entity_alias_name+".title3 like '%"+querywhere.get("title3")+"%'";
			}
			if(querywhere.containsKey("title4")){
				hql = hql+" and "+entity_alias_name+".title4 like '%"+querywhere.get("title4")+"%'";
			}
		}
		return hql;
	}

	@Override
	public List<Map<String, Object>> grid(Map<String, String> querywhere) {
		List<Map<String, Object>> resultList = null;
		try {
			Integer start = this.getGridStartOrSize(querywhere, 0, field_grid_start);
			Integer size = this.getGridStartOrSize(querywhere, 20, field_grid_size);
			String hql = this.getHql(querywhere);
			Map<String,String> gridsel = new HashMap<String,String>();
			gridsel.put(field_id, ""+entity_alias_name+".id as id ");
			gridsel.put(field_title, ""+entity_alias_name+".title1 as title1 ");
			gridsel.put("title2", ""+entity_alias_name+".title2 as title2 ");
			gridsel.put("title3", ""+entity_alias_name+".title3 as title3 ");
			gridsel.put("title4", ""+entity_alias_name+".title4 as title4 ");
			gridsel.put("title5", ""+entity_alias_name+".title5 as title5 ");
			resultList = this.queryMapDataList(hql, gridsel, start, size);
			return resultList;
		} catch (Exception e) {
			return new ArrayList<Map<String, Object>>();
		}
	}

	@Override
	public ISpecialTopicItemDao getDao() throws Exception {
		// TODO Auto-generated method stub
		return specialTopicItemDao;
	}

	
	
}
